package com.nc.delivery_project.client.departments;

import com.google.gwt.cell.client.TextCell;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.cellview.client.DataGrid;
import com.nc.delivery_project.client.composite.PagingDataGrid;
import com.nc.delivery_project.shared.proxy.DepartmentProxy;


public class DepartmentPagingDataGrid extends PagingDataGrid<DepartmentProxy> {

    @Override
    public void initTableColumns(DataGrid<DepartmentProxy> dataGrid, ColumnSortEvent.ListHandler<DepartmentProxy> sortHandler) {
    	 Column<DepartmentProxy, String> idCol = createIdCol();
         Column<DepartmentProxy, String> addressCol = createAddressCol();
         Column<DepartmentProxy, String> postalCodeCol = createPostalCodeCol();
         Column<DepartmentProxy, String> cityCol = createCityCol();
         Column<DepartmentProxy, String> stateCol = createStateCol();
         Column<DepartmentProxy, String> countryCol = createCountryCol();
         Column<DepartmentProxy, String> acceptedOrdersCol = createAcceptedOrdersCountryCol();
         Column<DepartmentProxy, String> issuedOrdersCol = createIssuedOrdersCol();
        
         dataGrid.addColumn(idCol, "ID");
         dataGrid.addColumn(countryCol, "Country");
         dataGrid.addColumn(stateCol, "State/Province");
         dataGrid.addColumn(cityCol, "City");
         dataGrid.addColumn(addressCol, "Address");
         dataGrid.addColumn(postalCodeCol, "Postal Code");
         dataGrid.addColumn(acceptedOrdersCol, "Accepted orders");
         dataGrid.addColumn(issuedOrdersCol, "Issued orders");
        
         
         
    }

	private Column<DepartmentProxy, String> createIssuedOrdersCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return String.valueOf(arg0.getDeptId()- 400);//нужно реальное поле IssuedOrders
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createAcceptedOrdersCountryCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return String.valueOf(arg0.getDeptId()-402);//нужно реальное поле AcceptedOrders
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createCountryCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return arg0.getCity().getStatePr().getCountry().getCountryTitle();
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createStateCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return arg0.getCity().getStatePr().getStateTitle();
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createIdCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return String.valueOf(arg0.getDeptId());
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createAddressCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return arg0.getAddress();
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createPostalCodeCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return arg0.getPostalCode();
			}
		};
		return col ;
	}

	private Column<DepartmentProxy, String> createCityCol() {
		Column<DepartmentProxy, String> col = new Column<DepartmentProxy, String>(new TextCell()) {
			
			@Override
			public String getValue(DepartmentProxy arg0) {
				return arg0.getCity().getCityTitle();
			}
		};
		return col ;
	}
   
}
